package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Getter
@Setter
public class Travel extends BaseDomain {
    public static final Integer STATE_COMMON = 0;   // 草稿
    public static final Integer STATE_AUDIT = 1;     // 待审核
    public static final Integer STATE_RELEASE = 2;     // 已发布
    public static final Integer STATE_REJECT = 1;     // 已拒绝

    // 标题
    private String title;
    // 出行时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    // 人均消费
    private String perExpends;
    // 出行天数
    private Integer days;
    // 和谁去
    private Integer person;
    // 作者
    private User author;
    // 创建时间
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
    private Date createTime;
    // 发行时间
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
    private Date releaseTime;
    // 是否公开
    private Boolean isPublic = false;
    // 地区
    private Region place;
    // 封面
    private String coverUrl;
    // 最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
    private Date lastUpdateTime;
    // 状态
    private Integer state = STATE_COMMON;

    // 游记内容
    private TravelContent travelContent;

    public String getStateName() {
        String temp = "草稿";
        if (state == STATE_AUDIT) {
            temp = "待审核";
        } else if (state == STATE_RELEASE) {
            temp = "已发布";
        } else if (state == STATE_REJECT) {
            temp = "已拒绝";
        }
        return temp;
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap();
        map.put("id", this.id);
        map.put("title", this.title);
        map.put("coverUrl", this.coverUrl);
        return JSONUtils.toJSONString(map);
    }

    public String getPersonName() {
        String temp = "";
        switch(state) {
            case 1:
                temp = "一个人的旅行";
                break;
            case 2:
                temp = "和父母";
                break;
            case 3:
                temp = "和朋友";
                break;
            case 4:
                temp = "和同事";
                break;
            case 5:
                temp = "和爱人";
                break;
            default:
                temp = "和其他";
        }
        return temp;
    }
}